package com.supply.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

public class LoadActivitiResources {

    //部署流程
    public static void main(String[] args) {

        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        configuration.setJdbcDriver("com.mysql.jdbc.Driver");
        configuration.setJdbcUrl("jdbc:mysql://localhost:3306/supply?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8");
        configuration.setJdbcUsername("root");
        configuration.setJdbcPassword("123");

        //如果当前数据库已经有表，则不创建，没有才创建
        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

        ProcessEngine processEngine = configuration.buildProcessEngine();
        System.out.println("流程引擎对象：" + processEngine);

        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment().name("采购申请流程")
                .addClasspathResource("bpmn/procurement.bpmn")
                .addClasspathResource("bpmn/procurement.png")
                .deploy();

        System.out.println("部署流程ID:" + deployment.getId());
        System.out.println("部署流程名称:" + deployment.getName());
    }
}
